package com.xinmachong.springcloud.controller;

import com.xinmachong.springcloud.entities.ApiResponse;
import com.xinmachong.springcloud.entities.Payment;
import com.xinmachong.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author meyer@HongYe
 */
@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;


    @PostMapping(value = "/create")
    public ApiResponse create(@RequestBody Payment payment) {
        int result = this.paymentService.create(payment);
        log.info("====插入结果：" + result);
        if (result > 0) {
            return new ApiResponse(200, "success", 1);
        }
        return new ApiResponse(444,"插入数据失败",null);
    }


    @GetMapping(value = "/get/{id}")
    public ApiResponse<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = this.paymentService.getPaymentById(id);
        if (payment != null) {
            return new ApiResponse<>(200,"success",payment);
        }
        return new ApiResponse<>(444,"没有对应记录,查询ID: "+id,null);
    }
}
